package com.example.spring_blog.common.util;

import com.example.spring_blog.pojo.dataobject.BlogInfo;
import com.example.spring_blog.pojo.dataobject.UserInfo;
import com.example.spring_blog.pojo.response.BlogInfoResponse;
import com.example.spring_blog.pojo.response.UserInfoResponse;
import org.apache.catalina.User;
import org.springframework.beans.BeanUtils;

public class BeanTransUtils {

    // 将BlogInfo转为BlogInfoResponse
    public static BlogInfoResponse trans(BlogInfo blogInfo) {
        if (blogInfo == null) {
            //TODO
            return null;
        }
        BlogInfoResponse blogInfoResponse = new BlogInfoResponse();
        BeanUtils.copyProperties(blogInfo, blogInfoResponse);
        return blogInfoResponse;
    }

    // 将UserInfo转为UserInfoResponse
    public static UserInfoResponse trans(UserInfo userInfo) {
        if (userInfo == null) {
            //TODO
            return null;
        }
        UserInfoResponse userInfoResponse = new UserInfoResponse();
        BeanUtils.copyProperties(userInfo, userInfoResponse);
        return userInfoResponse;
    }

    // 带有文章的数量
    public static UserInfoResponse trans(UserInfo userInfo, Integer articleNums) {
        if (userInfo == null) {
            //TODO
            return null;
        }
        UserInfoResponse userInfoResponse = new UserInfoResponse();
        BeanUtils.copyProperties(userInfo, userInfoResponse);
        userInfoResponse.setArticleNums(articleNums);
        return userInfoResponse;
    }

}
